import { _decorator, Camera, Component, find, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import {RoleName} from './RoleName'
@ccclass('Person')
export class Person extends Component {

    private labelNode:Node = null
    private camera:Camera = null
    private roleName:RoleName =null;
    start() {
        this.labelNode = this.node.getChildByName('labelNode')
        this.camera = find('Main Camera').getComponent(Camera)
        this.roleName = find('Canvas/roleName').getComponent(RoleName)
    }

    update(deltaTime: number) {
        
    }

     lateUpdate(dt: number): void {
        this.syncUILabel()
    }

    syncUILabel(){
        var wPos = this.labelNode.getWorldPosition();
        var sPos = this.camera.worldToScreen(wPos)
        this.roleName.showAt(sPos)
    }

    
}


